package com.zcdyy.rentalofhouse.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zcdyy.rentalofhouse.R;
import com.zcdyy.rentalofhouse.listener.OnItemClickListener;
import com.zcdyy.rentalofhouse.ui.adapter.PayStyleAdapter;
import com.zcdyy.rentalofhouse.utils.BaseTranslucentActivity;
import com.zcdyy.rentalofhouse.utils.DividerItemDecoration;
import com.zcdyy.rentalofhouse.utils.TextUtilsForFont;

import java.util.ArrayList;
import java.util.List;

public class PayStyleActivity extends BaseTranslucentActivity implements OnItemClickListener {
    private Toolbar toolBar;
    private ImageView ivBack;
    private RecyclerView recyclerView;
    private PayStyleAdapter adapter;
    private List<String> list = new ArrayList<>();
    private Class[] cls = {WholeRentDetailsActivity.class,SaleActivity.class
    ,SingleRentActivity.class,ShopsActivity.class};
    private int t = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_style);
        initData();
        initTitle();
        initView();
        bind();
    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null){
            String type = intent.getStringExtra("type");
            list.clear();
            switch (type){
                case "zhengzhu":
                    t = 0;
                    list.add("押一付三");
                    list.add("押一付一");
                    list.add("半年付");
                    list.add("一年付");
                    list.add("面议");
                    break;
                case "sale":
                    t = 1;
                    list.add("精装修");
                    list.add("简单装修");
                    list.add("豪华装修");
                    list.add("中等装修");
                    list.add("毛坯");
                    break;
                case "single":
                    t = 2;
                    list.add("主卧");
                    list.add("副卧");
                    list.add("隔断");
                    list.add("床位");break;
                case "shop":
                    t = 3;
                    list.add("商业街卖场");
                    list.add("写字楼配套");
                    list.add("住宅底商");
                    list.add("摊位柜台");
                    list.add("其他");break;
            }
        }

    }

    private void bind() {
        adapter = new PayStyleAdapter(this, list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        DividerItemDecoration decoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST);
        decoration.setDivider(R.drawable.divid_shape);
        recyclerView.addItemDecoration(decoration);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(this);
    }

    private void initTitle() {
        toolBar = (Toolbar) findViewById(R.id.toolBar);
        toolBar.setTitle("");
        setSupportActionBar(toolBar);
        toolBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        ((TextView) findViewById(R.id.tv_title)).setTextSize(TypedValue.COMPLEX_UNIT_PX,
                TextUtilsForFont.getFontSize(PayStyleActivity.this, 35));

        setOrChangeTranslucentColor(toolBar, null, getResources().getColor(R.color.colorBlue));
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recycler);
    }

    @Override
    public void onItemClick(int position) {
        Intent intent = new Intent(PayStyleActivity.this,cls[t]);
        intent.putExtra("payStyle",list.get(position));
        setResult(666,intent);
        finish();
    }
}
